package com.qk.management.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.qk.common.PageResult;
import com.qk.domain.customer.CustomerDO;
import com.qk.dto.customer.CustomerListDTO;
import com.qk.management.mapper.CustomerMapper;
import com.qk.management.service.CustomerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CustomerServiceImpl implements CustomerService {
    @Autowired
    private CustomerMapper customerMapper;
    @Override
    public PageResult<CustomerDO> selectByPage(CustomerListDTO customerListDTO) {
        PageHelper.startPage(customerListDTO.getPage(), customerListDTO.getPageSize());
        List<CustomerDO> customers = customerMapper.selectByPage(customerListDTO);
        Page<CustomerDO> page = (Page<CustomerDO>) customers;
        return PageResult.<CustomerDO>builder()
                .total(Long.valueOf(page.getTotal()).intValue())
                .rows(page.getResult())
                .build();
    }
}
